package priv.bruce.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import priv.bruce.entry.UserInfo;
import priv.bruce.service.UserService;

public class ModifyUserInformation extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private UserService userInfo = new UserService();
	UserInfo user;

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("application/json;charset=utf-8");
		UserInfo user = (UserInfo) request.getSession().getAttribute("user");

		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String addr1 = request.getParameter("shengfen");
		String addr2 = request.getParameter("city");
		String addr = addr1 + addr2;
		String mail = request.getParameter("mail");
		String phone = request.getParameter("phone");

		try {
			UserInfo aaa = userInfo.validUserInfo(username);
			System.out.println(aaa);

			int a = userInfo.modifyInformation((int) user.getUser_id(), username, password, mail, phone, addr);
			if (a > 0) {
				request.getSession().setAttribute("user", user);
			}
			response.getWriter().append(JSON.toJSONString(a));
			System.out.println("受影响行数" + a);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
